/* holder_ptr.h                  -*-C++-*-
 *
 *************************************************************************
 *
 * Copyright (C) 2011, Intel Corporation
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *   * Neither the name of Intel Corporation nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 **************************************************************************/

/**
 * @file holder_ptr.h
 *
 * @brief Implementation of holder_ptr<Type, Policy, Allocator> template.
 */

#ifndef INCLUDED_HOLDER_PTR_DOT_H
#define INCLUDED_HOLDER_PTR_DOT_H

#include <cilk/holder.h>
#include <cilk/reducer_ptr.h>

namespace cilk {

    template <typename Type,
              holder_policy Policy = holder_keep_indeterminate,
              typename Allocator = std::allocator<Type> >
    struct holder_ptr : reducer_ptr<holder_monoid<Type, Policy, Allocator> >
    {
    private:
        typedef reducer_ptr<holder_monoid<Type, Policy, Allocator> > base;

    public:
        /// Construct a null holder_ptr.
        holder_ptr();

        /// Construct holder_ptr whose primary object is at primary_p.
        explicit holder_ptr(Type* primary_p);

        /// Construct holder_ptr that shares the same primary object
        /// as p.  After construction, this hyperpointer can be used
        /// interchangeably with p.  This constructor is an implicit
        /// conversion constructor from the longhand type name.
        holder_ptr(const base& p);

        /// Make this hyperpointer share the same primary object as p.  After
        /// the assigment, this hyperpointer can be used interchangeably with
        /// p.
        holder_ptr& operator=(const base& h);
    };

/////////////////////////////////////////////////////////////////////////////
// Implementation of inline and template functions
/////////////////////////////////////////////////////////////////////////////

    template <typename Type, holder_policy Policy, typename Allocator>
    inline
    holder_ptr<Type, Policy, Allocator>::holder_ptr() 
        : base()
    {
    }

    template <typename Type, holder_policy Policy, typename Allocator>
    inline
    holder_ptr<Type, Policy, Allocator>::holder_ptr(Type* primary_p)
        : base(primary_p)
    {    
    }

    template <typename Type, holder_policy Policy, typename Allocator>
    inline
    holder_ptr<Type, Policy, Allocator>::holder_ptr(const base& p)
        : base(p)
    {    
    }

    template <typename Type, holder_policy Policy, typename Allocator>
    inline
    holder_ptr<Type, Policy, Allocator>&
    holder_ptr<Type, Policy, Allocator>::operator=(const base& p)
    {
        base::operator=(p);
        return *this;
    }

} // Close namespace cilk

#endif // ! defined(INCLUDED_HOLDER_PTR_DOT_H)
